/*
 * @Author: alan_mf
 * @Date: 2023-03-07 21:05:23
 * @LastEditors: upp24 1246815351@qq.com
 * @LastEditTime: 2023-12-08 17:44:32
 * @FilePath: /pure-admin-thin-i18n/src/api/user.ts
 * @Description:
 *
 */
import { http } from "@/utils/http";
import { baseUrlApi } from "./utils";
export type UserResult = {
  [x : string] :
  | string
  | VNode<RendererNode, RendererElement, { [key : string] : any }>
  | (() => VNode<RendererNode, RendererElement, { [key : string] : any }>);
  admin_name : string;
  admin_pass : string;
  admin_status : number;
  admin_create : number;
  admin_update : number;
  role_id : number;
  admin_nick : string;
  token : string;
  admin_id : Date;
  success : boolean;
  code : number;
  data : {
    admin : any[];
    data : any[];
    total : number;
    admin_id : any;
    /** 用户名 */
    username : string;
    /** 当前登陆用户的角色 */
    roles : Array<string>;
    /** `token` */
    token : string;
    /** `token` */
    accessToken : string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken : string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires : Date;
  };
};

export type RefreshTokenResult = {
  success : boolean;
  data : {
    /** `token` */
    accessToken : string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken : string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires : Date;
  };
};

/** 登录 */
export const getLogin = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("admin/aLogin"), {
    data
  });
};
/** 管理员信息 */
export const getInfo = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("auth/admin/author"), {
    data
  });
};
/** 管理员列表 */
export const getUserList = (data ?: object) => {
  return http.request<UserResult>("get", baseUrlApi(`admin/auth/admin/list?page=${data.page}&pagesize=${data.pagesize}&role_id=${data.role_id}`), {
    data
  });
};
//管理员添加
export const addInsert = (data) => {
  return http.request("post", baseUrlApi("admin/auth/admin/insert"), {
    data
  });
};


/** 修改/添加管理员 */
export const getUpdate = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("admin/auth/admin/update"), {
    data
  });
};
/** 删除管理员 */
export const getDelete = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("admin/auth/admin/delete"), {
    data
  });
};
/**角色信息 */
export const getRoleInfo = (data ?: object) => {
  return http.request<UserResult>("get", baseUrlApi(`admin/auth/role/info?role_id=${data.roleId}`), {
    data
  });
};
/** 角色列表 */
export const getRoleList = (data ?: object) => {
  return http.request<UserResult>("get", baseUrlApi(`admin/auth/role/list`), {
    data
  });
};
/** 修改/添加角色 */
export const getRoleUpdate = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("auth/role/update"), {
    data
  });
};
/** 删除角色 */
export const getRoleDelete = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("auth/role/delete"), {
    data
  });
};
/** 刷新token */
export const refreshTokenApi = (data ?: object) => {
  return http.request<RefreshTokenResult>("post", baseUrlApi("login"), {
    data
  });
};

/** 添加/更新路由 */
export const getRoutesAdd = (data ?: object) => {
  return http.request<RefreshTokenResult>(
    "post",
    baseUrlApi("auth/route/update"),
    {
      data
    }
  );
};
//删除路由
export const getRoutesDelete = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("auth/route/delete"), {
    data
  });
};
//直推统计
export const getDirect = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("user/suggest"), {
    data
  });
};

//合同列表
export const getContractList = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("user/contract/list"), {
    data
  });
};

//合同详情
export const getContractInfo = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("user/contract/info"), {
    data
  });
};

//合同提交
export const getContractUpdate = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("user/contract/update"), {
    data
  });
};

//获取推荐人
export const getRecommend = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("user/partner"), {
    data
  });
};

//验证验证码
export const getCheckVerify = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("login/check"), {
    data
  });
};

//获取股东分红
export const getDivvyList = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("user/divvy/list"), {
    data
  });
};

//分红分配

export const grantDivvy = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("user/divvy/grant"), {
    data
  });
};


// 上传头像
export const getuFile = (data ?: object) => {
  return http.request<UserResult>("post", baseUrlApi("admin/uFile"), {
    data
  });
};


// 管理员信息
export const getInfoAdmin = (data ?: object) => {
  return http.request<UserResult>("get", baseUrlApi(`admin/auth/admin/info?admin_id=${data.admin_id}`), {
    data
  });
};
